package com.nuoniu.sibanyun.service.erp.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.erp.ErpAccountRuleSet;
import com.nuoniu.sibanyun.mapper.erp.ErpAccountRuleSetMapper;
import com.nuoniu.sibanyun.service.erp.IErpAccountRuleSetService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 账套-选项设置 服务实现类
 * </p>
 *
 * @author baiqiang
 * @since 2020-11-07
 */
@Service
public class ErpAccountRuleSetServiceImpl extends ServiceImpl<ErpAccountRuleSetMapper, ErpAccountRuleSet> implements IErpAccountRuleSetService {

    @Override
    public void initDefErpAccountRuleSet(UserInfo userInfo, Integer accountId) {
        List<ErpAccountRuleSet> erpAccountRuleSets = listDefErpAccountRuleSet();
        if(erpAccountRuleSets.size() > 0){
            erpAccountRuleSets.forEach(item->{
                item.setAccountId(accountId);
                item.setCompanyId(userInfo.getCompanyId());
                item.setId(null);
            });
            saveBatch(erpAccountRuleSets);
        }

    }

    @Override
    public List<ErpAccountRuleSet> listDefErpAccountRuleSet() {
        QueryWrapper<ErpAccountRuleSet> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id",1);
        queryWrapper.eq("account_id",0);
        List<ErpAccountRuleSet> list = list(queryWrapper);
        return list;
    }
}
